package org.example.mqtexxt.mqserver.core;

import java.io.Serializable;
import java.util.UUID;

public class Message implements Serializable {

    BasicProperties basicProperties = new BasicProperties();

    private byte[] body;

    private transient long offsetBeg = 0;

    private transient long offsetEnd = 0;

    private byte isValid = 0x1;

    public String getMessageId(){
        return basicProperties.getMessageId();
    }
    public void setMessageId(String messageId){
        basicProperties.setMessageId(messageId);
    }

    public String getRoutingKey(){
        return basicProperties.getRoutingKey();
    }
    public void setRoutingKey(String routingKey){
        basicProperties.setRoutingKey(routingKey);
    }

    public int  getDeliverMode() {
        return basicProperties.isDeliverMode();
    }
    public void setDeliverMode(int  deliverMode){
        basicProperties.setDeliverMode(deliverMode);
    }

    public  Message createMessage(String messageId, byte[] body, String routingKey){
        Message message = new Message();
        if(basicProperties != null){
            message.setBasicProperties(basicProperties);
        }
        message.setMessageId("MM-"+ UUID.randomUUID());
        message.setBody(body);
        message.setRoutingKey(routingKey);
        return message;
    }


    public BasicProperties getBasicProperties() {
        return basicProperties;
    }

    public void setBasicProperties(BasicProperties basicProperties) {
        this.basicProperties = basicProperties;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public long getOffsetBeg() {
        return offsetBeg;
    }

    public void setOffsetBeg(long offsetBeg) {
        this.offsetBeg = offsetBeg;
    }

    public long getOffsetEnd() {
        return offsetEnd;
    }

    public void setOffsetEnd(long offsetEnd) {
        this.offsetEnd = offsetEnd;
    }

    public  byte isValid() {
        return isValid;
    }

    public void setValid(byte valid) {
        isValid = valid;
    }
}
